<template>
  <div>
    <!-- 搜索添加栏 -->
    <Row>
      <Card>
        <Form ref="search" :model="searchData" :rules="searchReg" :label-width="100">
          <Row>
            <i-col>
              <FormItem label="搜索事项" prop="name">
                <Input
                  v-model="searchData.incentive"
                  suffix="ios-search"
                  placeholder="请输入事项名称"
                  style="width: auto"
                >
                  <Icon type="ios-search" slot="suffix" />
                </Input>
              </FormItem>
            </i-col>
            <i-col :xs="24" :md="12" :lg="6">
              <FormItem label="加分类别" prop="name">
                <Select v-model="searchData.pointsType" style="width:200px" clearable>
                  <Option
                    v-for="item in listType"
                    :value="item.id + ''"
                    :key="item.id"
                  >{{ item.typeName }}</Option>
                </Select>
              </FormItem>
            </i-col>
            <i-col :xs="24" :md="12" :lg="6">
              <FormItem label="表彰单位" prop="name">
                <Input
                  v-model="searchData.recognitionUnit"
                  placeholder="请输入表彰单位"
                  style="width: auto"
                ></Input>
              </FormItem>
            </i-col>
            <i-col :xs="24" :md="12" :lg="6">
              <FormItem label="被表彰单位" prop="name">
                <Select
                  filterable
                  clearable
                  placeholder="请选择被表彰单位"
                  v-model="searchData.departCode"
                  style="width:150px"
                >
                  <Option
                    v-for="item in getDepartmentList"
                    :value="item.departcode"
                    :key="item.departcode"
                  >{{ item.department }}</Option>
                </Select>
              </FormItem>
            </i-col>
          </Row>
          <Row>
            <i-col :xs="24" :md="12" :lg="6">
              <FormItem label="审核状态" prop="name">
                <Select v-model="searchData.audit" style="width:200px" clearable>
                  <Option value="0">全部</Option>
                  <Option value="1">已审核</Option>
                  <Option value="2">未审核</Option>
                  <Option value="3">回退</Option>
                </Select>
              </FormItem>
            </i-col>
            <i-col :xs="24" :md="12" :lg="6">
              <FormItem label="年份">
                <DatePicker
                  type="year"
                  format="yyyy"
                  @on-change="searchSelectYear"
                  placeholder="按年份搜索"
                  style="width:185px"
                  v-model="searchData.dateTime"
                ></DatePicker>
              </FormItem>
            </i-col>
          </Row>
          <FormItem>
            <Button
              v-if="btnAccess.query"
              type="primary"
              style="marigin:0 20px"
              :loading="searchLoading"
              @click="searchSubmit(10,1)"
            >提交搜索</Button>
            <Button @click="submitReset">重置搜索</Button>
          </FormItem>
        </Form>
      </Card>
    </Row>
    <!-- 表格栏 -->
    <Row style="margin-top:10px">
      <div class="btn-arrs">
        <Button type="info" v-if="btnAccess.add" @click="appendMatter">添加事项</Button>
        <Tooltip content="点击此按钮可查看 自己事项 或者 查看全部事项" placement="top-start" max-width="330">
          <Button type="warning" @click="switchTable(tableName)">{{tableName}}</Button>
        </Tooltip>
        <Button type="success" @click="exportIncentive" v-if="isSpuerAdmins.add">导出激励事项</Button>
      </div>
      <!-- 自己事项 -->
      <Card v-show="isShowSelfTable">
        <Table border :columns="incentiveHead" :data="incentiveData" :loading="tabelLoading"></Table>
        <div style="margin-top:15px;text-align:center;">
          <Page
            @on-change="pageNumberChange"
            :page-size="pageSize"
            :total="pageTotal"
            @on-page-size-change="pageSizeChange"
            show-elevator
            show-sizer
          />
        </div>
      </Card>
      <!-- 全部事项 -->
      <Card v-show="!isShowSelfTable">
        <Table border :columns="allDataHead" :data="allData"></Table>
      </Card>
    </Row>
    <!-- 图表展示区 -->
    <!-- <Row :gutter="20" style="margin-top: 20px;">
      <i-col :md="24" :lg="12" style="margin-bottom: 20px;">
        <Card shadow>
          <chart-pie v-if="pieData.length" style="height: 400px;" :value="pieData" text="加分类别占比"></chart-pie>
          <Spin size="large" fix v-if="isPieLoading"></Spin>
        </Card>
      </i-col>
      <i-col :md="24" :lg="12" style="margin-bottom: 20px;">
        <Card shadow>
          <example
            v-if="isEample"
            style="height: 400px;"
            :title="exampleTitle"
            :data="lineData"
            :yName="'项'"
          />
          <Spin size="large" fix v-if="isExampleLoading"></Spin>
        </Card>
      </i-col>
    </Row>-->

    <!-- 增加修改模态框 -->
    <Drawer
      :title="DrawerTitle"
      v-model="isShowMatters"
      width="820"
      :mask-closable="false"
      :styles="styles"
      @on-close="closeDrawer"
    >
      <Form ref="matters" :model="mattersForm" :rules="mattersReg" :label-width="110">
        <Row>
          <i-col :xs="24" :md="12" :lg="12">
            <FormItem label="事项名称" prop="incentive">
              <Input style="width:285px;" v-model="mattersForm.incentive" placeholder="请输入事项名称"></Input>
            </FormItem>
          </i-col>
        </Row>
        <Row>
          <i-col :xs="24" :md="12" :lg="12">
            <FormItem label="加分类别" prop="pointsType">
              <Select v-model="mattersForm.pointsType" placeholder="请选择加分类别" @on-change="queryType">
                <Option
                  v-for="item in listType"
                  :value="item.id + ''"
                  :key="item.id"
                >{{ item.typeName }}</Option>
              </Select>
            </FormItem>
          </i-col>
          <i-col :xs="24" :md="12" :lg="12">
            <FormItem label="加分类别子类" prop="typeItemId">
              <Select v-model="mattersForm.typeItemId" placeholder="请选择加分类别子类">
                <Option
                  v-for="items in listTypeItem"
                  :value="items.id"
                  :key="items.id"
                >{{ items.itemName }}</Option>
              </Select>
            </FormItem>
          </i-col>
        </Row>
        <Row>
          <i-col :xs="24" :md="12" :lg="12">
            <FormItem label="表彰单位" prop="recognitionUnit">
              <Input v-model="mattersForm.recognitionUnit" placeholder="请输入表彰单位名称"></Input>
            </FormItem>
          </i-col>
          <i-col :xs="24" :md="12" :lg="12">
            <FormItem label="被表彰单位" prop="commendedUnit">
              <Input v-model="mattersForm.commendedUnit" placeholder="请输入被表彰单位名称"></Input>
            </FormItem>
          </i-col>
        </Row>
        <Row>
          <i-col :xs="24" :md="12" :lg="12">
            <FormItem label="加分分值" prop="point">
              <InputNumber
                v-model="mattersForm.point"
                :max="10"
                :min="0"
                :step="0.1"
                style="width:285px;"
              ></InputNumber>
            </FormItem>
          </i-col>
          <i-col :xs="24" :md="12" :lg="12">
            <FormItem label="年份" prop="dateTime">
              <DatePicker
                type="year"
                format="yyyy"
                :value="mattersForm.dateTime"
                placeholder="请选择年份"
                style="width: 285px"
                @on-change="formSelectYear"
              ></DatePicker>
            </FormItem>
          </i-col>
        </Row>
        <Row>
          <i-col :xs="24" :md="12" :lg="12">
            <FormItem label="证明材料名称" prop="fileName">
              <Input v-model="mattersForm.fileName" placeholder="请输入证明材料名称"></Input>
            </FormItem>
          </i-col>
          <i-col :xs="24" :md="12" :lg="12"></i-col>
        </Row>
        <FormItem label="证明材料附件" prop="image">
          <div class="demo-upload-list" v-for="(item,index) in uploadList" :key="index">
            <template v-if="item.status === 'finished'">
              <img :src="HOST+item.url" />
              <div class="demo-upload-list-cover">
                <Icon type="ios-eye-outline" @click.native="handleView(item.url)"></Icon>
                <Icon type="ios-trash-outline" @click.native="handleRemove(item)"></Icon>
              </div>
            </template>
            <template v-else>
              <Progress v-if="item.showProgress" :percent="item.percentage" hide-info></Progress>
            </template>
          </div>
          <!-- action="/upload/fileUpload"  线上
              action="api/upload/fileUpload" 本地
          -->
          <Upload
            ref="upload"
            :show-upload-list="false"
            :default-file-list="defaultList"
            :on-success="handleSuccess"
            :format="['jpg','jpeg','png']"
            :max-size="2048"
            :on-format-error="handleFormatError"
            :on-exceeded-size="handleMaxSize"
            :before-upload="handleBeforeUpload"
            multiple
            type="drag"
            :action="importImgUrl"
            style="display: inline-block;width:58px;"
          >
            <div style="width: 58px;height:58px;line-height: 58px;">
              <Icon type="ios-camera" size="20"></Icon>
            </div>
          </Upload>
          <Modal title="查看图片" v-model="visible">
            <img :src="HOST + imgName " v-if="visible" style="width: 100%" />
          </Modal>
        </FormItem>

        <FormItem label="附件" prop="otherFileId">
          <Upload
            ref="upload2"
            :before-upload="handleUpload"
            :on-success="handleSuccess2"
            :format="['pdf']"
            :on-format-error="handleFormatError2"
            :action="importFileUrl"
          >
            <Button icon="ios-cloud-upload-outline">上传附件</Button>
          </Upload>
          <div v-if="file !== null">
            文件名: {{ file.name }}
            <Button type="primary" @click="upload">点击上传</Button>
          </div>
        </FormItem>

        <FormItem label="回退原因" v-if="mattersForm.reason !== null">
          <Input
            v-model="mattersForm.reason"
            disabled
            type="textarea"
            placeholder="Enter something..."
          />
        </FormItem>
        <div style="margin-top:10px">
          <Card dis-hover>
            <h4 style="margin:10px;">加分类别</h4>
            <Tag
              style="display:block;"
              type="dot"
              color="primary"
              v-for="(item , index) in listType"
              :key="index"
            >{{item.typeClass+ ": " + item.typeName }}</Tag>
          </Card>
        </div>
      </Form>
      <div class="demo-drawer-footer">
        <Button
          v-if="btnAccess.upd"
          type="primary"
          :loading="submitLoading"
          @click="submitDrawer"
        >上传提交</Button>
        <Button style="margin-right: 8px" @click="closeDrawer">关闭</Button>
      </div>
    </Drawer>
  </div>
</template>
<script>
import { HOST, URL } from "@/libs/util";
import { ChartPie } from "_c/charts";
import { incentiveAjax, deleteAjax } from "@/api/city";
import { categoryAjax } from "@/api/incentives";
import example from "@/view/single-page/home/example.vue";
// 查询路径
const QUERYTYPE_URL = "/incentive/getItemList";
export default {
  data() {
    return {
      // 是否为超级管理员
      isSpuerAdmins: {
        add: true,
        action: "inline-block"
      },
      // 增删改查权限按钮
      btnAccess: {
        add: true,
        add2: "inline-block",
        del: "inline-block",
        upd: true,
        query: true
      },
      HOST: "", // HTTP//192....
      isEample: false,
      exampleTitle: "各月获得表彰项目数量",
      isShowMatters: false, // 增加修改模态框
      addMattersTitle: "", // title
      lookRowContent: {}, // 看一行内容
      DrawerTitle: "",
      pageTotal: 10, // 总页数
      pageSize: 10, // 页数
      pageNumber: 1, // 页码
      pieData: [], // 饼图数据
      lineData: [], // 折线图数据
      searchLoading: false, // 搜索Loading
      submitLoading: false, // 提交Loading
      tabelLoading: true, // 表格Loading
      isExampleLoading: false, // 折线图Loaidng
      isPieLoading: true, // 饼图Loading
      searchData: {
        incentive: "", // 事项名称
        pointsType: "", // 加分类别
        recognitionUnit: "", // 表彰单位
        departCode: "", // 被表彰单位
        audit: "", // 审核状态,
        dateTime: "", // 年份
        table: "" // 1:查看自己  2 查看全部
      },
      // 表单
      mattersForm: {
        incentive: "", // 事项名称
        pointsType: "", // 一类
        typeItemId: "", // 二类
        recognitionUnit: "", // 表彰单位
        // commendedUnit: "", // 被表彰单位
        departCode: "", // 被表彰单位
        audit: "", // 审核状态,
        dateTime: "", // 年份
        point: null, // 分值
        fileName: "", // 证明材料名称
        fileId: [], // 材料附件Id
        reason: null,
        otherFileId: "", // 附件id
        // value1: [], // 类别选项值
        data: [] // 类别选项数据
      },
      listType: [], // 大类类别
      listTypeItem: [], // 小类类别
      category: [], // 类别数据
      styles: {
        height: "calc(100% - 55px)",
        overflow: "auto",
        paddingBottom: "53px",
        position: "static"
      },
      searchReg: {},
      mattersReg: {
        incentive: [
          {
            required: true,
            message: "请输入事项名称",
            trigger: "blur"
          }
        ],
        recognitionUnit: [
          {
            required: true,
            message: "请输入表彰单位名称",
            trigger: "blur"
          }
        ],
        point: [
          {
            required: true,
            type: "number",
            message: "请输入加分分值",
            trigger: "change"
          }
        ],
        commendedUnit: [
          {
            required: true,
            message: "请输入被表彰单位名称",
            trigger: "blur"
          }
        ],
        fileName: [
          {
            required: true,
            message: "请输入证明材料名称",
            trigger: "blur"
          }
        ],
        materialVal: [
          {
            required: true,
            message: "请填写加分分值",
            trigger: "blur"
          }
        ],
        dateTime: [
          {
            required: true,
            type: "string",
            message: "请选择时间",
            trigger: "change"
          }
        ],
        pointsType: [
          {
            required: true,
            type: "string",
            message: "请选择加分类别",
            trigger: "change"
          }
        ],
        typeItemId: [
          {
            required: true,
            type: "number",
            message: "请选择加分类别子项",
            trigger: "change"
          }
        ]
      },
      incentiveHead: [
        {
          title: "序号",
          type: "index",
          width: 80,
          align: "center"
        },
        {
          title: "事项名称",
          key: "incentive"
        },
        {
          title: "表彰单位",
          key: "recognitionUnit"
        },
        {
          title: "被表彰单位",
          key: "commendedUnit"
        },
        {
          title: "所在单位",
          key: "department"
        },
        {
          title: "类别名称",
          key: "typeName",
          width: 110
        },
        {
          title: "审批状态",
          key: "audit",
          width: 120,
          align: "center",
          render: (h, params) => {
            var color = "";
            var text = "";
            var isDisabled = false;
            switch (params.row.audit) {
              case "0":
                color = "default";
                text = "未审核";
                break;
              case "1":
                color = "success";
                text = "已审核";
                break;
              case "2":
                color = "error";
                text = "回退";
                break;
              default:
                break;
            }
            return h(
              "Button",
              {
                props: {
                  type: color,
                  disabled: isDisabled
                }
              },
              text
            );
          }
        },
        {
          title: "证明材料",
          key: "fileName"
        },
        {
          title: "操作",
          key: "action",
          width: 210,
          align: "center",
          render: (h, params) => {
            var isDisabled = false;
            if (params.row.audit === "1") {
              isDisabled = true;
            }
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      // const id = params.row.id;
                      this.$router.push({
                        name: "incentive_details",
                        params: {
                          // id: id,
                          incentiveItem: params.row,
                          audit: false // 带参数 判断是否进行审批操作
                        }
                      });
                    }
                  }
                },
                "查看"
              ),
              h(
                "Button",
                {
                  props: {
                    disabled: isDisabled
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      this.isShowMatters = true;
                      this.DrawerTitle = "正向激励-编辑";
                      var row = params.row;
                      this.mattersForm = Object.assign(row, {
                        point: parseFloat(row.point)
                      });
                      this.mattersForm = JSON.parse(
                        JSON.stringify(this.mattersForm)
                      );
                      // 获取图片信息
                      this.uploadList = row.fileList;
                      this.$refs.upload.fileList = this.uploadList;
                      this.queryType();
                    }
                  }
                },
                "编辑"
              ),
              h(
                "Icon",
                {
                  props: {
                    type: "md-trash",
                    size: 24
                  },
                  style: {
                    display: this.btnAccess.del
                  },
                  on: {
                    click: () => {
                      this.removeIncentive(params.row);
                    }
                  }
                },
                "删除"
              )
            ]);
          }
        }
      ],
      incentiveData: [],
      // upload
      defaultList: [],
      imgName: "",
      visible: false,
      uploadList: [],
      // 查看全部事项表格
      allDataHead: [
        {
          title: "序号",
          type: "index",
          width: 60,
          align: "center"
        },
        {
          title: "事项名称",
          key: "incentive",
          width: 300
        },
        {
          title: "表彰单位",
          key: "recognitionUnit",
          width: 300
        },
        {
          title: "被表彰单位",
          key: "commendedUnit",
          width: 300
        },
        {
          title: "加分类别",
          key: "pointsType",
          width: 150
        },
        {
          title: "加分分值",
          key: "point",
          width: 100
        },
        {
          title: "审批状态",
          key: "audit",
          width: 100,
          align: "center",
          render: (h, params) => {
            var color = "";
            var text = "";
            var isDisabled = false;
            switch (params.row.audit) {
              case "0":
                color = "default";
                text = "未审核";
                break;
              case "1":
                color = "success";
                text = "已审核";
                break;
              case "2":
                color = "error";
                text = "回退";
                break;
              default:
                break;
            }
            return h(
              "Button",
              {
                props: {
                  type: color,
                  disabled: isDisabled
                }
              },
              text
            );
          }
        },
        {
          title: "年份",
          key: "dateTime",
          width: 100
        },
        {
          title: "证明材料",
          key: "fileName",
          width: 150
        }
      ],
      allData: [],
      isShowSelfTable: true,
      tableName: "查看全部事项",
      file: null,
      importImgUrl: URL + "/upload/fileUpload", // 上传图片url
      importFileUrl: URL + "/upload/fileUpload", // 上传附件url
      categoryData: [] // 类别数据
    };
  },
  components: {
    ChartPie,
    example
  },
  methods: {
    submitReset() {
      this.submitLoading = false;
      this.searchData = {
        incentive: "", // 事项名称
        pointsType: "", // 加分类别
        recognitionUnit: "", // 表彰单位
        commendedUnit: "", // 被表彰单位
        audit: "", // 审核状态,
        dateTime: "" // 年份
      };
    },
    // 搜索
    searchSubmit(pageSize, pageNumber) {
      this._getIncentive(this.searchData, pageSize, pageNumber);
    },
    // form表单选择年份
    formSelectYear(year) {
      this.mattersForm.dateTime = year;
    },
    // 关闭抽屉
    closeDrawer() {
      this.isShowMatters = false;
      this.submitLoading = false;
      this.$refs["matters"].resetFields();
      if (this.DrawerTitle === "正向激励-添加") {
        var formData = this.getImageList();
        if (formData.length) {
          const url = "/upload/delete";
          deleteAjax({ formData, url })
            .then(result => {
              if (result.data.code === "200") {
                // 清空updateList
                this.$refs.upload.fileList.splice(0, this.uploadList.length);
              } else {
              }
            })
            .catch(err => {
              console.log(err);
            });
        }
      } else {
        // 清空updateList
        this.uploadList = this.$refs.upload.fileList;
      }
    },
    // 抽屉里的提交按钮
    submitDrawer() {
      var url = "";
      // 获取上传图片的Id
      if (!this.getImageList().length && this.mattersForm.otherFileId === "") {
        this.$Message.error("佐证材料 和 附件 至少上传一个 ");
        return;
      }
      this.mattersForm = Object.assign(this.mattersForm, {
        fileId: this.getImageList().join(",")
      });
      // 根据DrawerTitle
      if (this.DrawerTitle === "正向激励-添加") {
        url = "/incentive/insert";
      } else if (this.DrawerTitle === "正向激励-编辑") {
        url = "/incentive/update";
      }
      this.$refs["matters"].validate(valid => {
        if (valid) {
          this.submitLoading = true;
          const keyOne = "incentiveEntity";
          this._incentiveAjax(url, this.mattersForm, keyOne).then(result => {
            this.submitLoading = false;
            if (result.code === "200") {
              this.isShowMatters = false;
              this._getIncentive("", this.pageSize, this.pageNumber);
              this.$Message.success("添加成功");
            } else {
              this.$Message.error("添加失败!");
            }
          });
        } else {
          this.$Message.error("带*为必填项");
        }
      });
    },
    // 删除
    removeIncentive(id) {
      this.$Modal.confirm({
        title: "删除事项",
        content: "<h3>删除该事项后将无法恢复</h3>",
        onOk: () => {
          const url = "/incentive/delete";
          const keyOne = "incentiveEntity";
          this._incentiveAjax(url, id, keyOne, "", "").then(result => {
            if (result.code === "200") {
              this._getIncentive(
                this.searchData,
                this.pageSize,
                this.pageNumber
              );
            } else {
              this.$Message.error("删除失败！请刷新页面后尝试");
            }
          });
        }
      });
    },
    // 页码
    pageNumberChange(pageNumber) {
      this.pageNumber = pageNumber;
      this._getIncentive(this.searchData, this.pageSize, this.pageNumber);
    },
    // 页数
    pageSizeChange(pageSize) {
      this.pageSize = pageSize;
      this._getIncentive(this.searchData, this.pageSize, this.pageNumber);
    },
    // 添加事项
    appendMatter() {
      this.isShowMatters = true;
      this.DrawerTitle = "正向激励-添加";
      this.$refs.upload.fileList.splice(0, this.uploadList.length);
      // 清除ID
      if (this.mattersForm.id !== undefined) {
        this.mattersForm.id = "";
      }
    },
    // 搜索框年份选择
    searchSelectYear(year) {
      this.searchData.dateTime = year;
    },
    // AJAX
    _incentiveAjax(url, formData, keyOne, pageSize, pageNumber) {
      formData = Object.assign(formData, {
        pageSize,
        pageNumber
      });
      const keyTwo = "";
      return new Promise((resolve, reject) => {
        incentiveAjax({ formData, url, keyOne, keyTwo })
          .then(result => {
            if (result.data !== undefined) {
              resolve(result.data);
            } else {
              reject(err);
            }
          })
          .catch(err => {
            console.log(err);
          });
      });
    },
    // 搜索
    _getIncentive(formData, pageSize, pageNumber) {
      this.tabelLoading = true;
      formData = Object.assign(formData, {
        pageSize,
        pageNumber
      });
      const url = "/incentive/query";
      const keyOne = "incentiveFilter";
      const keyTwo = "";
      incentiveAjax({ formData, url, keyOne, keyTwo })
        .then(result => {
          this.tabelLoading = false;
          this.incentiveData = [];
          if (result.data.code === "200") {
            this.listType = result.data.results.listType;
            result.data.results.list.forEach(item => {
              this.incentiveData.push(item.incentive);
              // 查看全部
              // this.allData.push(item.incentive);
            });
            this.pageTotal = parseInt(result.data.results.total) * 10;
            this.$Message.success("查询成功");
          } else {
            this.$Message.error("查询失败");
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 上传图片========================
    getImageList() {
      const fileList = this.$refs.upload.fileList;
      var idList = [];
      fileList.forEach(item => {
        idList.push(item.id);
      });
      return idList;
    },
    // 查看图片
    handleView(name) {
      this.imgName = name;
      this.visible = true;
    },
    handleRemove(file) {
      // 从服务器上删除
      const formData = [file.id];
      const url = "/upload/delete";
      deleteAjax({ formData, url })
        .then(result => {
          if (result.data.code === "200") {
            const fileList = this.$refs.upload.fileList;
            this.$refs.upload.fileList.splice(fileList.indexOf(file), 1);
          } else {
            this.$Message.error("删除图片失败！请刷新页面重试");
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    handleSuccess(res, file, fileList) {
      file.name = file.name;
      file.url = file.response.results.fileUrl;
      file.id = file.response.results.fileId;
      this.uploadList = this.$refs.upload.fileList;
    },
    handleFormatError(file) {
      this.$Notice.warning({
        title: "上传图片格式错误",
        desc: "图片 " + file.name + " 格式错误, 请换成JPG/PNG."
      });
    },
    handleMaxSize(file) {
      this.$Notice.warning({
        title: "上传图片失败",
        desc: "图片 " + file.name + " 大小超出了2M"
      });
    },
    handleBeforeUpload() {
      const check = this.uploadList.length < 5;
      if (!check) {
        this.$Notice.warning({
          title: "最多只能上传5张图片"
        });
      }
      return check;
    },
    /**
     * @param {name} 参数
     * 工作督查
     */
    switchTable(name) {
      if (name === "查看自己事项") {
        this.isShowSelfTable = true;
        this.tableName = "查看全部事项";
      } else if (name === "查看全部事项") {
        this.isShowSelfTable = false;
        this.tableName = "查看自己事项";
        // 请求查看全部
        const url = "/incentive/query";
        const keyOne = "incentiveFilter";
        let data = { table: "2" }; // 2为请求查看全部
        this.allData = [];
        this._incentiveAjax(url, data, keyOne).then(result => {
          if (result.code === "200") {
            result.results.list.forEach(item => {
              this.allData.push(item.incentive);
            });
            this.$Message.success(result.message);
          } else {
            this.$Message.error(result.message);
          }
        });
      }
    },
    // 上传附件
    // 阻止自动上传文件
    handleUpload(file) {
      this.file = file;
      return false;
    },
    // 上传文件
    handleSuccess2(res, file, fileList) {
      if (res.code === "200") {
        // 上传成功保存id

        this.mattersForm.otherFileId = res.results.fileId;
        console.log(res.results.fileId);
        this.$Notice.success({
          title: res.message
        });
      } else {
        this.$Notice.success({
          title: res.message
        });
      }
    },
    // 点击上传文件
    upload() {
      this.$refs.upload2.post(this.file);
      setTimeout(() => {
        this.file = null;
      }, 1500);
    },
    // 验证上传格式
    handleFormatError2(file) {
      this.$Notice.warning({
        title: "文件格式错误",
        desc: "文件" + file.name + " 格式错误, 请选择 pdf 格式"
      });
    },
    // 查询类别数据
    _getData(formData, url) {
      const keyOne = "incentiveFilter";
      categoryAjax({ formData, url, keyOne })
        .then(result => {
          if (result.data.code === "200") {
            this.listTypeItem = result.data.results;
            this.$Message.success("查询成功");
          } else {
            this.$Message.error("查询失败");
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 查询类别事件
    queryType(value) {
      let data = this.mattersForm;
      this._getData(data, QUERYTYPE_URL);
    },
    // 导出激励事件
    exportIncentive() {
      window.open(URL + "/incentive/exportIncentive");
    }
  },
  mounted() {
    this.uploadList = this.$refs.upload.fileList;
  },
  computed: {
    getDepartmentList() {
      return this.$store.state.user.departmentList;
    }
  },
  created() {
    this.HOST = HOST;
    // 获取tabel数据
    this._getIncentive(this.searchData, this.pageSize, this.pageNumber);
    // // 饼图数据
    // const keyOne = "incentiveFilter";
    // var pieUrl = "/incentive/pointType";
    // this._incentiveAjax(pieUrl, this.searchData, keyOne, "", "").then(
    //   result => {
    //     if (result.code === "200") {
    //       var pie = []; // 饼图
    //       result.results.pointType.forEach(item => {
    //         var obj = Object.assign(
    //           {},
    //           {
    //             value: item.num === null ? 0 : item.num,
    //             name: item.pointsType + "类"
    //           }
    //         );
    //         pie.push(obj);
    //       });
    //       result.results.monthType.forEach(item => {
    //         var lineObj = Object.assign(
    //           {},
    //           {
    //             name: item.monthTime + "月",
    //             score: item.num
    //           }
    //         );
    //         this.lineData.push(lineObj);
    //       });
    //       this.isEample = true;
    //       this.pieData = pie;
    //       this.isPieLoading = false;
    //     }
    //   }
    // );

    // this._getData("", QUERYTYPE_URL);

    // 获取按钮权限
    let btnAccess = sessionStorage.getItem("btnaccess");
    this.globalFunction(btnAccess);

    // 获取是否为超级管理员
    let isSuperAdmin = sessionStorage.getItem("isSuperAdmin");
    this.globalFunction2(isSuperAdmin);
  }
};
</script>
<style>
.demo-upload-list {
  display: inline-block;
  width: 60px;
  height: 60px;
  text-align: center;
  line-height: 60px;
  border: 1px solid transparent;
  border-radius: 4px;
  overflow: hidden;
  background: #fff;
  position: relative;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
  margin-right: 4px;
}
.demo-upload-list img {
  width: 100%;
  height: 100%;
}
.demo-upload-list-cover {
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.6);
}
.demo-upload-list:hover .demo-upload-list-cover {
  display: block;
}
.demo-upload-list-cover i {
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  margin: 0 2px;
}
.demo-drawer-footer {
  width: 100%;
  position: absolute;
  bottom: 0;
  left: 0;
  border-top: 1px solid #e8e8e8;
  padding: 10px 16px;
  text-align: right;
  background: #fff;
}
</style>
